﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;

namespace Nyamr
{
    partial class NyamrService : ServiceBase
    {
        public NyamrService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            if (File.Exists("nyamr.log")) File.Delete("nyamr.log");
            var log = new StreamWriter("nyamr.log");
            try
            {
                log.WriteLine("Started plan.xml");
                log.Flush();
                var plan = Plan.Load("plan.xml");
                log.WriteLine("Loaded plan.xml");
                log.Flush();
                Nyamr.Run(plan);
                log.WriteLine("Finished plan.xml");
                log.Flush();
                log.Close();
                Stop();
            }
            catch (Exception e)
            {
                log.WriteLine("Error {0}", e);
                log.WriteLine(e);
                log.Flush();
                log.Close();
            }
        }

        protected override void OnStop()
        {
            // TODO: Add code here to perform any tear-down necessary to stop your service.
        }
    }
}
